package com.rzx.mybackend.springTask;

import com.rzx.mybackend.enums.tasks.GamePublishTaskStatus;
import com.rzx.mybackend.service.Impl.GameServiceImpl;
import lombok.RequiredArgsConstructor;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

/**
 * CleanGamePublishMemory
 *
 * @author renzhexian
 * @date 2025/9/17
 */
@Component
@RequiredArgsConstructor
public class CleanGamePublishMemory {

    private final GameServiceImpl gameServiceImpl;

    @Scheduled(fixedRate = 3600000) // 每小时执行一次
    public void cleanCompletedTasks() {
        gameServiceImpl.getGameTasksConcurrentHashMap().forEach((gameId, task) -> {
            if (task.getTaskStatus().equals(GamePublishTaskStatus.COMPLETED.getCode())) {
                gameServiceImpl.deleteGamePublishTask(gameId);
            }
        });

    }
}
